package cn.ztydata.teachingsystem.heaven.dao.redis;

import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Repository;

/**
 * 资源->习题 Redis类
 *
 * @author chenxin
 * @since 2015-02-04
 */
@Repository
public class ResExerciseDao extends BaseRedisDao {
    /**
     * 判断资源是否被习题引用
     * @param resourceId 资源编号
     * @return boolean
     *
     * @author chenxin
     * @since 2015-02-04
     */
    public boolean isUsed(final long resourceId) {
        //获取Set操作
        SetOperations<String, Long> setOperations = redisTemplate.opsForSet();

        logger.debug("check resource isUsed");

        //获取Set大小
        return setOperations.size(KeyUtils.generateKey(ExerciseResDao.RES_EXERCISE, resourceId)) > 0;
    }
}
